<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>后台管理系统</title>
	    <meta name="author" content="BaiYY"/>
	    <meta charset="utf-8">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <meta name="renderer" content="webkit">
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
	    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
	</head>
	<body>

		<!--右边侧栏开始-->
		<div class="right-sidebar" style="max-width: 1200px;">
			<ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
				<li role="presentation"><a href="goodsList.html">商品列表</a></li>
				<li role="presentation" class="active"><a href="goodsAdd.html">添加商品</a></li>
				<li role="presentation"><a href="goodsSearch.html">商品搜索</a></li>
			</ul>
			
		<div class="row">
			<div class="col-md-12">
				<div class="input-group">
					<input type="hidden" id="goods_id" value={$goods_id}>
					<span class="input-group-addon">商品名称</span>
					<input class="form-control" type="text" name="goods_name" id="goods_name"/>
				</div>
				<div class="alert alert-danger hide" role="alert" id="goods_name-tips"></div>
	
				<div class="input-group">
					<span class="input-group-addon">销售价格</span>
					<input class="form-control" type="text" name="price" id="price" />
				</div>
				<div class="alert alert-danger hide" role="alert" id="price-tips"></div>
	
				<div class="input-group">
					<span class="input-group-addon">{:L(GAME_RESOURCE)}数量</span>
					<input class="form-control" type="text" name="number" id="number"/>
				</div>
				<div class="alert alert-danger hide" role="alert" id="number-tips"></div>
				
				<div class="input-group">
					<span class="input-group-addon">是否上线</span>
					<div class="form-control">
						<input type="radio" name="status" value="1" id="status1"> 是
						<input type="radio" name="status" value="0" id="status0">否
					</div>
				</div>

				<div class="input-group" id="roles">
					<span class="input-group-addon">显示条件</span>
					<div class="form-control" >
						<input type="radio"  name="role" value="1" id="role1">一级可见
						&emsp;
						<input type="radio"  name="role" value="2" id="role2">二级可见
						&emsp;
						<if condition='$level gt 2'>
						<input type="radio"  name="role" value="3" id="role3">三级可见
						&emsp;
						</if>
						<input type="radio"  name="role" value="10" id="role">都可见
					</div>
				</div>
	
				<div class="input-group">
					<span class="input-group-addon">商品描述</span>
					<textarea class="form-control" class='textarea' name="description" id="description" rows="5"></textarea>
				</div>
				<p></p>
				<button type="submit" class="btn btn-primary center-block" id="submit">保存</button>
			</div>
		</div>
		<script type="text/javascript">
			$(function () {
			    var goods_id = $("#goods_id").val();
				$.ajax({
					type:"get",
					url:"{:U('Admin/Main/goodsModifyData')}?goods_id=" + goods_id,
					success:function (data) {
//					    console.log(data);
					    if(data != 'nodata') {
					        if(data.status == 1) {
					            $("#status1").attr("checked",true);
							}else if(data.status == 0) {
					            $("#status0").attr("checked",true);
							}
							switch (data.goods_level) {
								case "1":
								    $("#role1").attr("checked",true);
								    break;
								case "2":
								    $("#role2").attr("checked",true);
								    break;
								case "3":
								    $("#role3").attr("checked",true);
								    break;
								default:
								    $("#role").attr("checked",true);
							}
					        $("#goods_name").val(data.goods_name);
					        $("#price").val(data.price);
					        $("#number").val(data.number);
							$("#description").html(data.description);
						}
                    }
				});
            });
			$("#submit").click(function(){
				var goods_name = $.trim($('#goods_name').val());
				var price = $.trim($('#price').val());
				var number = $.trim($("#number").val());
				var status = $('[name="status"]:checked').val();
				var description = $.trim($('#description').val());
                var level = $('[name="role"]:checked').val();
				
				var params = {
					goods_name: goods_name,
					price: price,
					number: number,
					status: status,
                    goods_level:level,
					description: description
				};
				var url="{:U('Admin/Main/goodsSave')}?goods_id={$goods_id}";
				$.ajax({
					type:"post",
					url:url,
					dataType:"json",
					data:params,
					success:function(data){
						if(data == "success") {
							alert("修改成功！");
							window.location.href="{:U('Admin/Main/goodsList')}";
						}else if(data == "failure") {
							alert("修改失败！");
						}
					}
				});
			})
		</script>
	</body>
</html>
